﻿using System;
//using NPOI.SS.UserModel;
//using NPOI.XSSF.UserModel;
using System.IO;
using Business.Base.Utils;
using Business.Base;
using Business.Base.Model;

using Microsoft.Office.Interop.Excel;
using Business.Base.Service;
using System.Linq;


namespace Business.CentrifugalPump.Perf
{
    public class CentrifugalPumpPerfExperimentExcelManager : IExperimentExcelManager
    {


        /*
        public String SaveExperiment(CentrifugalPumpPerfExperiment experiment,String chartPath)
        {
            IWorkbook wk = null;
            //var ext1 = Path.GetExtension(templateFile).ToLower();
            using (FileStream fs = File.Open(Config.PerfExperimentReportTemplatePath, FileMode.Open,  FileAccess.Read))
            {
                wk = new XSSFWorkbook(fs);
                fs.Close();
            }
            ISheet sheet = wk.GetSheetAt(0);

            #region 第一行的设置
            IRow row = sheet.GetRow(2);

            //试验编号
            row.GetCell(2).SetCellValue(experiment.Code);
            //额定功率
            row.GetCell(6).SetCellValue(experiment.PumpRatedPower/1000.0);
            //电机额定效率
            row.GetCell(8).SetCellValue(experiment.MotorRatedEfficiency);
            //流量
            row.GetCell(10).SetCellValue(experiment.MeasureFlow);           


            //流量是否合格
            row.GetCell(11).SetCellValue(experiment.MeasureFlowIsPass==1?"是":"否");
            #endregion

            #region 第二行的设置
            row = sheet.GetRow(3);

            //泵型号
            row.GetCell(2).SetCellValue(experiment.PumpModel);
            //额定效率
            row.GetCell(6).SetCellValue(experiment.MotorRatedEfficiency);
            //扬程
            row.GetCell(10).SetCellValue(experiment.MeasureHead);
            //扬程是否合格
            row.GetCell(11).SetCellValue(experiment.MeasureFlowIsPass == 1 ? "是" : "否");
            #endregion

            #region 第三行的设置
            row = sheet.GetRow(4);

            //额定流量
            row.GetCell(2).SetCellValue(experiment.PumpRatedFlow);
            //额定转速
            row.GetCell(6).SetCellValue(experiment.MotorRatedSpeed);
            //功率
            row.GetCell(10).SetCellValue(experiment.MeasurePower/1000.0);
            //功率是否合格
            row.GetCell(11).SetCellValue(experiment.MeasurePowerIsPass == 1 ? "是" : "否");
            #endregion

            #region 第四行的设置
            row = sheet.GetRow(5);

            //额定扬程
            row.GetCell(2).SetCellValue(experiment.PumpRatedHead);
            //温度
            //row.GetCell(6).SetCellValue();
            //泵效率
            row.GetCell(10).SetCellValue(experiment.MeasureEff);
            //泵效率是否合格
            row.GetCell(11).SetCellValue(experiment.MeasureEffIsPass);

            //XB
            row.GetCell(12).SetCellValue(experiment.ExperimentLevel);
            #endregion

            #region 第五行的设置
            row = sheet.GetRow(6);

            //入口直径
            row.GetCell(2).SetCellValue(experiment.DInlet);
            //入口长度
            row.GetCell(6).SetCellValue(experiment.LInlet);
            #endregion

            #region 第六行的设置
            row = sheet.GetRow(7);

            //出口直径
            row.GetCell(2).SetCellValue(experiment.DOutlet);
            //出口长度
            row.GetCell(6).SetCellValue(experiment.LOutlet);
            #endregion

            #region 第七行的设置
            row = sheet.GetRow(8);

            //测试人
            row.GetCell(2).SetCellValue(experiment.ExperimentOwner);
            //交点流量
            row.GetCell(6).SetCellValue(experiment.CrossFlow);
            //交点扬程
            row.GetCell(10).SetCellValue(experiment.CrossHead);


            #endregion

            #region 第七行的设置
            row = sheet.GetRow(9);

            //测试人
            row.GetCell(2).SetCellValue(experiment.CreateTime.ToString("d"));
            //交点流量
            //row.GetCell(6).SetCellValue("??");
            //交点扬程
            //row.GetCell(10).SetCellValue("??");


            #endregion

            #region 填写记录

            int rowIndex = 13;
            ICellStyle cellStyle;
            IDataFormat dataFormat;
            IFont font;
            ICell cell;

            foreach (CentrifugalPumpPerfExperimentRecord record in experiment.RecordList)
            {
                cellStyle = wk.CreateCellStyle();
                dataFormat = wk.CreateDataFormat();
                font = wk.CreateFont();

                font.FontName = "宋体";
                font.FontHeightInPoints = 9;
                //设置为文本格式，也可以为 text，即 dataFormat.GetFormat("text");
                cellStyle.DataFormat = dataFormat.GetFormat("@");
                cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;    //下边框线
                cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;      //左边框线
                cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;     //右边框线
                cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;       //上边框线
                cellStyle.Alignment = HorizontalAlignment.Center;

                cellStyle.SetFont(font);
                cellStyle.VerticalAlignment = VerticalAlignment.Center;

                row = sheet.CreateRow(rowIndex);

                row.HeightInPoints = 20;

                cell = row.CreateCell(0);
                cell.SetCellValue(rowIndex-12);
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(1);                
                cell.SetCellValue(record.WorkingFlow.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(2);
                cell.SetCellValue(record.PresureIn.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(3);
                cell.SetCellValue(record.PresureOut.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(4);
                cell.SetCellValue(record.ElectricCurrent.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(5);
                cell.SetCellValue(record.Voltage.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(6);
                cell.SetCellValue((record.WorkingPower/1000.0).ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(7);
                cell.SetCellValue(record.WorkingHead.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(8);
                cell.SetCellValue(record.WorkingSpeed.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(9);
                cell.SetCellValue(record.StpFlow.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(10);
                cell.SetCellValue(record.StpHead.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(11);
                cell.SetCellValue((record.StpShaftPower/1000).ToString("F2"));
                cell.CellStyle = cellStyle;


                cell = row.CreateCell(12);
                cell.SetCellValue(record.StpPumpEfficiency.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(13);
                cell.SetCellValue(record.StpGroupEfficiency.ToString("F2"));
                cell.CellStyle = cellStyle;
                rowIndex++;
            }

            #endregion

            #region  空出一行

            cellStyle = wk.CreateCellStyle();
            dataFormat = wk.CreateDataFormat();
            font = wk.CreateFont();

            font.FontName = "宋体";
            font.FontHeightInPoints = 9;
            //设置为文本格式，也可以为 text，即 dataFormat.GetFormat("text");
            cellStyle.DataFormat = dataFormat.GetFormat("@");
            cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.None;    //下边框线
            cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;      //左边框线
            cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;     //右边框线
            cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.None;       //上边框线
            cellStyle.Alignment = HorizontalAlignment.Center;

            cellStyle.SetFont(font);
            cellStyle.VerticalAlignment = VerticalAlignment.Center;
            row = sheet.CreateRow(rowIndex);
            row.HeightInPoints = 20;
            for (int i = 0; i < 13; i++)
            {
                cell = row.CreateCell(i);
                cell.CellStyle = cellStyle;
            }
            //row.RowStyle = cellStyle;
            sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(rowIndex, rowIndex, 0, 13));
            #endregion

            #region 插入图片
            cellStyle = wk.CreateCellStyle();
            dataFormat = wk.CreateDataFormat();
            font = wk.CreateFont();

            font.FontName = "宋体";
            font.FontHeightInPoints = 9;
            //设置为文本格式，也可以为 text，即 dataFormat.GetFormat("text");
            cellStyle.DataFormat = dataFormat.GetFormat("@");
            cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;    //下边框线
            cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;      //左边框线
            cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;     //右边框线
            cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.None;       //上边框线
            cellStyle.Alignment = HorizontalAlignment.Center;

            cellStyle.SetFont(font);
            cellStyle.VerticalAlignment = VerticalAlignment.Center;
            rowIndex++;
            row = sheet.CreateRow(rowIndex);
            row.HeightInPoints = 500;
            for (int i = 0; i < 14; i++)
            {
                cell = row.CreateCell(i);
                cell.CellStyle = cellStyle;
            }
            //row.RowStyle = cellStyle;
            sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(rowIndex, rowIndex, 0, 13));
            



            IDrawing drawing = sheet.CreateDrawingPatriarch();
            byte[] buff = File.ReadAllBytes(chartPath);
            int pic = wk.AddPicture(buff,PictureType.PNG);
            XSSFClientAnchor anchor = new XSSFClientAnchor(0, 10, 0, 10, 0, rowIndex, 13,rowIndex+1);
            //anchor.AnchorType = 2;
            drawing.CreatePicture(anchor, pic);
            #endregion

            String saveFile = Config.PerfExperimentReportDir+"\\"+experiment.Code+".xlsx";
            try
            {
                FileStream fileStream = File.OpenWrite(saveFile);
                wk.Write(fileStream);
                fileStream.Close();
            }
            catch 
            {
                
                return null;
                //Debug.WriteLine(e.Message);
            }
            return saveFile;
        }
        
        static void Main(string[] args)
        { 
            CentrifugalPumpPerfExperimentExcelManager perfExperimentExcelManager = new CentrifugalPumpPerfExperimentExcelManager();
            CentrifugalPumpPerfExperiment experiment = new CentrifugalPumpPerfExperiment();
            experiment.Code = "code";
            experiment.PumpRatedPower = 1.0f;
            experiment.MotorRatedEfficiency =2.0f;
            experiment.PumpRatedFlow = 3.0f;
            experiment.PumpModel = "pumpModel";
            experiment.PumpRatedFlow = 4.0f;
            experiment.MotorRatedSpeed = 5.0f;
            experiment.DInlet = 6.0f;


            experiment.DOutlet = 7.0f;
            experiment.ExperimentOwner = "owner";

            CentrifugalPumpPerfExperimentRecord record = new CentrifugalPumpPerfExperimentRecord();
            record.PresureOut = 1.0f;
            record.PresureIn = 2.0f;
            record.StpFlow = 3.0f;
            record.WorkingFlow = 4.0f;
            record.WorkingHead = 5.0f;
            record.StpHead = 6.0f;
            record.WorkingPower = 7.0f;
            record.StpGroupEfficiency = 8.0f;
            record.StpPumpEfficiency = 9.0f;
            record.ElectricCurrent = 10.0f;
            record.WorkingSpeed = 11.0f;

            experiment.RecordList.Add(record);

            record = new CentrifugalPumpPerfExperimentRecord();
            record.PresureOut = 11.0f;
            record.PresureIn = 21.0f;
            record.StpFlow = 31.0f;
            record.WorkingFlow = 41.0f;
            record.WorkingHead = 51.0f;
            record.StpHead = 16.0f;
            record.WorkingPower = 71.0f;
            record.StpGroupEfficiency = 8.10f;
            record.StpPumpEfficiency = 9.0f;
            record.ElectricCurrent = 110.10f;
            record.WorkingSpeed = 111.0f;

            experiment.RecordList.Add(record);

            //perfExperimentExcelManager.SaveExperiment(experiment);
       }
        */

        /*
        protected override void setExcel(Experiment exp, IWorkbook wk)
        {
            ISheet sheet = wk.GetSheetAt(0);
            CentrifugalPumpPerfExperiment experiment = (CentrifugalPumpPerfExperiment)exp;
            IRow row = sheet.GetRow(0);
            row.GetCell(0).SetCellValue(experiment.Customer);

            row = sheet.GetRow(2);
            #region 第一行
            //试验编号
            row.GetCell(2).SetCellValue(experiment.Code);
            //额定功率
            row.GetCell(6).SetCellValue(experiment.PumpRatedPower / 1000.0);
            //电机额定效率
            row.GetCell(8).SetCellValue(experiment.MotorRatedEfficiency);
            //流量
            row.GetCell(10).SetCellValue(experiment.MeasureFlow);


            //流量是否合格
            row.GetCell(11).SetCellValue(experiment.MeasureFlowIsPass ? "是" : "否");
#endregion

            #region 第二行的设置
            row = sheet.GetRow(3);

            //泵型号
            row.GetCell(2).SetCellValue(experiment.PumpModel);
            //额定效率
            row.GetCell(6).SetCellValue(experiment.MotorRatedEfficiency.ToString("F2"));
            //扬程
            row.GetCell(10).SetCellValue(experiment.MeasureHead.ToString("F2"));
            //扬程是否合格
            row.GetCell(11).SetCellValue(experiment.MeasureFlowIsPass  ? "是" : "否");
            #endregion

            #region 第三行的设置
            row = sheet.GetRow(4);

            //额定流量
            row.GetCell(2).SetCellValue(experiment.PumpRatedFlow);
            //额定转速
            row.GetCell(6).SetCellValue(experiment.MotorRatedSpeed);
            //功率
            row.GetCell(10).SetCellValue(experiment.MeasurePower / 1000.0);
            //功率是否合格
            row.GetCell(11).SetCellValue(experiment.MeasurePowerIsPass  ? "是" : "否");
            #endregion

            #region 第四行的设置
            row = sheet.GetRow(5);

            //额定扬程
            row.GetCell(2).SetCellValue(experiment.PumpRatedHead);
            //温度
            //row.GetCell(6).SetCellValue();
            //泵效率
            row.GetCell(10).SetCellValue(experiment.MeasureEff.ToString("F2"));
            //泵效率是否合格
            row.GetCell(11).SetCellValue(experiment.MeasureEffIsPass ? "是" : "否");

            //XB
            row.GetCell(12).SetCellValue(experiment.ExperimentLevel );
            #endregion

            #region 第五行的设置
            row = sheet.GetRow(6);

            //入口直径
            row.GetCell(2).SetCellValue(experiment.DInlet);
            //入口长度
            row.GetCell(6).SetCellValue(experiment.ZInlet);
            #endregion

            #region 第六行的设置
            row = sheet.GetRow(7);

            //出口直径
            row.GetCell(2).SetCellValue(experiment.DOutlet);
            //出口长度
            row.GetCell(6).SetCellValue(experiment.ZOutlet);
            #endregion

            #region 第七行的设置
            row = sheet.GetRow(8);

            //测试人
            row.GetCell(2).SetCellValue(experiment.ExperimentOwner);
            //交点流量
            row.GetCell(6).SetCellValue(experiment.CrossFlow.ToString("F2"));
            //交点扬程
            row.GetCell(10).SetCellValue(experiment.CrossHead.ToString("F2"));


            #endregion

            #region 第七行的设置
            row = sheet.GetRow(9);

            //测试人
            row.GetCell(2).SetCellValue(experiment.CreateTime.ToString("d"));
            //交点流量
            //row.GetCell(6).SetCellValue("??");
            //交点扬程
            //row.GetCell(10).SetCellValue("??");


            #endregion

            #region 填写记录

            int rowIndex = 13;
            ICellStyle cellStyle;
            IDataFormat dataFormat;
            IFont font;
            ICell cell;

            foreach (CentrifugalPumpPerfExperimentRecord record in experiment.RecordList)
            {
                cellStyle = wk.CreateCellStyle();
                dataFormat = wk.CreateDataFormat();
                font = wk.CreateFont();

                font.FontName = "宋体";
                font.FontHeightInPoints = 9;
                //设置为文本格式，也可以为 text，即 dataFormat.GetFormat("text");
                cellStyle.DataFormat = dataFormat.GetFormat("@");
                cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;    //下边框线
                cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;      //左边框线
                cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;     //右边框线
                cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;       //上边框线
                cellStyle.Alignment = HorizontalAlignment.Center;

                cellStyle.SetFont(font);
                cellStyle.VerticalAlignment = VerticalAlignment.Center;

                row = sheet.CreateRow(rowIndex);

                row.HeightInPoints = 20;

                cell = row.CreateCell(0);
                cell.SetCellValue(rowIndex - 12);
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(1);
                cell.SetCellValue(record.WorkingFlow.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(2);
                cell.SetCellValue(record.PresureIn.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(3);
                cell.SetCellValue(record.PresureOut.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(4);
                cell.SetCellValue(record.ElectricCurrent.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(5);
                cell.SetCellValue(record.Voltage.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(6);
                cell.SetCellValue((record.WorkingPower / 1000.0).ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(7);
                cell.SetCellValue(record.WorkingHead.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(8);
                cell.SetCellValue(record.WorkingSpeed.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(9);
                cell.SetCellValue(record.StpFlow.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(10);
                cell.SetCellValue(record.StpHead.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(11);
                cell.SetCellValue((record.StpShaftPower / 1000).ToString("F2"));
                cell.CellStyle = cellStyle;


                cell = row.CreateCell(12);
                cell.SetCellValue(record.StpPumpEfficiency.ToString("F2"));
                cell.CellStyle = cellStyle;

                cell = row.CreateCell(13);
                cell.SetCellValue(record.StpGroupEfficiency.ToString("F2"));
                cell.CellStyle = cellStyle;
                rowIndex++;
            }

            #endregion

            #region  空出一行

            cellStyle = wk.CreateCellStyle();
            dataFormat = wk.CreateDataFormat();
            font = wk.CreateFont();

            font.FontName = "宋体";
            font.FontHeightInPoints = 9;
            //设置为文本格式，也可以为 text，即 dataFormat.GetFormat("text");
            cellStyle.DataFormat = dataFormat.GetFormat("@");
            cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.None;    //下边框线
            cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;      //左边框线
            cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;     //右边框线
            cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.None;       //上边框线
            cellStyle.Alignment = HorizontalAlignment.Center;

            cellStyle.SetFont(font);
            cellStyle.VerticalAlignment = VerticalAlignment.Center;
            row = sheet.CreateRow(rowIndex);
            row.HeightInPoints = 20;
            for (int i = 0; i < 13; i++)
            {
                cell = row.CreateCell(i);
                cell.CellStyle = cellStyle;
            }
            //row.RowStyle = cellStyle;
            sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(rowIndex, rowIndex, 0, 13));
            #endregion

            #region 插入图片
            cellStyle = wk.CreateCellStyle();
            dataFormat = wk.CreateDataFormat();
            font = wk.CreateFont();

            font.FontName = "宋体";
            font.FontHeightInPoints = 9;
            //设置为文本格式，也可以为 text，即 dataFormat.GetFormat("text");
            cellStyle.DataFormat = dataFormat.GetFormat("@");
            cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;    //下边框线
            cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;      //左边框线
            cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;     //右边框线
            cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.None;       //上边框线
            cellStyle.Alignment = HorizontalAlignment.Center;

            cellStyle.SetFont(font);
            cellStyle.VerticalAlignment = VerticalAlignment.Center;
            rowIndex++;
            row = sheet.CreateRow(rowIndex);
            row.HeightInPoints = 500;
            for (int i = 0; i < 14; i++)
            {
                cell = row.CreateCell(i);
                cell.CellStyle = cellStyle;
            }
            //row.RowStyle = cellStyle;
            sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(rowIndex, rowIndex, 0, 13));




            IDrawing drawing = sheet.CreateDrawingPatriarch();
            byte[] buff = File.ReadAllBytes(experiment.ChartPath);
            int pic = wk.AddPicture(buff, PictureType.PNG);
            XSSFClientAnchor anchor = new XSSFClientAnchor(0, 10, 0, 10, 0, rowIndex, 13, rowIndex + 1);
            //anchor.AnchorType = 2;
            drawing.CreatePicture(anchor, pic);
            #endregion

            String saveFile = experiment.FilePath;
            try
            {
                FileStream fileStream = File.OpenWrite(saveFile);
                wk.Write(fileStream);
                fileStream.Close();
            }
            catch
            {

                return ;
                //Debug.WriteLine(e.Message);
            }
            return ;
        }*/

        

        



        public void setExcel(Experiment exp, Workbook wk)
        {

            Worksheet sheet = wk.Sheets[1];
            CentrifugalPumpPerfExperiment experiment = (CentrifugalPumpPerfExperiment)exp;

            sheet.Rows[1].Cells[1].Value = experiment.Customer;
            sheet.Rows[1].Cells[10].Value = experiment.Customer;


            #region 第一行
            //试验编号
            sheet.Rows[3].Cells[3].Value = experiment.PumpModel;
            //额定流量
            sheet.Rows[3].Cells[6].Value = Decimal.Round((Decimal)(experiment.PumpRatedFlow));
            //电机效率
            sheet.Rows[3].Cells[9].Value = Decimal.Round((Decimal)(experiment.MotorRatedEfficiency));

            #endregion

            #region 第二行的设置
            //试验编号
            sheet.Rows[4].Cells[3].Value = experiment.ExperimentCode;
            //额定扬程
            sheet.Rows[4].Cells[6].Value = (Double)Decimal.Round((Decimal)experiment.PumpRatedHead, 2);
            //额定转速
            sheet.Rows[4].Cells[9].Value = (Double)Decimal.Round((Decimal)experiment.ImpellerDia * 1000, 2);

            #endregion

            #region 第三行的设置


            //样品型号

            sheet.Rows[5].Cells[3].Value = experiment.PumpCode;
            sheet.Rows[5].Cells[6].Value = Decimal.Round((Decimal)experiment.PumpRatedEfficiency, 2);
            //额定功率
            sheet.Rows[5].Cells[9].Value = Decimal.Round((Decimal)experiment.PumpRatedPower, 2);


            #endregion

            #region 第四行的设置
            /*

            //额定扬程
            sheet.Rows[6].Cells[3].Value = Decimal.Round((Decimal)experiment.PumpRatedHead, 2);

            //电机额定效率
            sheet.Rows[6].Cells[7].Value = Decimal.Round((Decimal)experiment.MotorRatedEfficiency, 2);

            //泵效率
            sheet.Rows[6].Cells[11].Value = experiment.PumpModel;
            //编号
            sheet.Rows[6].Cells[12].Value = experiment.ExperimentCode;*/
            #endregion


            #region 填写第二页的规定值和实测值

            //额定流量
            sheet.Rows[4].Cells[11].Value = experiment.PumpRatedFlow;
            sheet.Rows[4].Cells[12].Value = experiment.PumpRatedHead;
            sheet.Rows[4].Cells[13].Value = experiment.PumpRatedPower;
            sheet.Rows[4].Cells[14].Value = experiment.PumpRatedEfficiency;
            sheet.Rows[4].Cells[15].Value = experiment.ExperimentLevel;

            double measureFlow = Double.IsNaN(experiment.MeasureFlow) ? 0 : experiment.MeasureFlow;
            double measureHead = Double.IsNaN(experiment.MeasureHead) ? 0 : experiment.MeasureHead;
            double measurePower = Double.IsNaN(experiment.MeasurePower) ? 0 : experiment.MeasurePower;
            double measureEff = Double.IsNaN(experiment.MeasureEff) ? 0 : experiment.MeasureEff;


            sheet.Rows[5].Cells[11].Value = Decimal.Round((Decimal)measureFlow, 2);
            sheet.Rows[5].Cells[12].Value = Decimal.Round((Decimal)measureHead, 2);
            sheet.Rows[5].Cells[13].Value = Decimal.Round((Decimal)measurePower, 2);
            sheet.Rows[5].Cells[14].Value = Decimal.Round((Decimal)measureEff, 2);
            sheet.Rows[5].Cells[15].Value = (experiment.MeasurePowerIsPass && experiment.MeasureHeadIsPass && experiment.MeasureEffIsPass) ? "是" : "否";



            sheet.Rows[6].Cells[11].Value = experiment.PumpModel;
            sheet.Rows[6].Cells[15].Value = experiment.ExperimentCode;


            #endregion

            #region 填写记录

            int rowIndex = 8;
            //按流量值从小到大排序
           
            foreach (CentrifugalPumpPerfExperimentRecord record in experiment.RecordList.OrderBy(e => e.WorkingFlow))
            {
                sheet.Rows[rowIndex + 1].Cells[1].Value = (rowIndex - 8)+1;
                sheet.Rows[rowIndex + 1].Cells[2].Value = Decimal.Round((Decimal)record.WorkingFlow, 2);
                sheet.Rows[rowIndex + 1].Cells[3].Value = Decimal.Round((Decimal)record.PresureIn, 2);
                sheet.Rows[rowIndex + 1].Cells[4].Value = Decimal.Round((Decimal)record.PresureOut, 2);
                sheet.Rows[rowIndex + 1].Cells[5].Value = Decimal.Round((Decimal)record.Voltage, 2);
                sheet.Rows[rowIndex + 1].Cells[6].Value = Decimal.Round((Decimal)record.ElectricCurrent, 2);
                sheet.Rows[rowIndex + 1].Cells[7].Value = Decimal.Round((Decimal)(record.WorkingPower / 1000.0),2);
                sheet.Rows[rowIndex + 1].Cells[8].Value = Decimal.Round((Decimal)(record.WorkingSpeed), 2);
                sheet.Rows[rowIndex + 1].Cells[9].Value = Decimal.Round((Decimal)(record.Temperature), 2);

                rowIndex++;
            }

            #endregion

            sheet.Rows[24].Cells[8].Value = experiment.MotorRatedSpeed;
            

            rowIndex = 26;
            foreach (CentrifugalPumpPerfExperimentRecord record in experiment.RecordList.OrderBy(e => e.WorkingFlow))
            {
                sheet.Cells[rowIndex + 1, 1].Value = (rowIndex - 26)+1;
                sheet.Cells[rowIndex + 1, 2].Value = Decimal.Round((Decimal)record.StpFlow, 2);
                sheet.Cells[rowIndex + 1, 3].Value = Decimal.Round((Decimal)record.WorkingHead, 2);
                sheet.Cells[rowIndex + 1, 4].Value = Decimal.Round((Decimal)record.StpHead, 2);
                sheet.Cells[rowIndex + 1, 5].Value = Decimal.Round((Decimal)(record.StpShaftPower ), 2);
                sheet.Cells[rowIndex + 1, 6].Value = Decimal.Round((Decimal)record.StpGroupEfficiency, 2);
                sheet.Cells[rowIndex + 1, 7].Value = Decimal.Round((Decimal)record.StpPumpEfficiency, 2);


                rowIndex++;
            }
            sheet.Rows[45].Cells[3].Value = experiment.ExperimentOwner;
            sheet.Rows[45].Cells[8].Value = experiment.CreateTime;
            sheet.Rows[45].Cells[11].Value = experiment.ExperimentOwner;
            sheet.Rows[45].Cells[15].Value = experiment.CreateTime;

            return;
        }
    }
}
